home *** CD-ROM | disk | FTP | other *** search
/ Erotic Games: Memory / Erotic Games: Memory.iso / mac / air_installers / AdobeAIR.exe / setup.swf / scripts / mx / managers / CursorManagerImpl.as < prev    next >
Text File  |  2009-02-12  |  17KB  |  518 lines

  1. package mx.managers
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.InteractiveObject;
  5.    import flash.display.Sprite;
  6.    import flash.display.Stage;
  7.    import flash.events.ContextMenuEvent;
  8.    import flash.events.Event;
  9.    import flash.events.EventDispatcher;
  10.    import flash.events.IOErrorEvent;
  11.    import flash.events.MouseEvent;
  12.    import flash.events.ProgressEvent;
  13.    import flash.text.TextField;
  14.    import flash.text.TextFieldType;
  15.    import flash.ui.Mouse;
  16.    import mx.core.ApplicationGlobals;
  17.    import mx.core.EventPriority;
  18.    import mx.core.FlexSprite;
  19.    import mx.core.mx_internal;
  20.    import mx.styles.CSSStyleDeclaration;
  21.    import mx.styles.StyleManager;
  22.    
  23.    use namespace mx_internal;
  24.    
  25.    public class CursorManagerImpl implements ICursorManager
  26.    {
  27.       
  28.       mx_internal static const VERSION:String = "3.0.0.0";
  29.       
  30.       private static var instance:ICursorManager;
  31.        
  32.       
  33.       private var showSystemCursor:Boolean = false;
  34.       
  35.       private var nextCursorID:int = 1;
  36.       
  37.       private var systemManager:ISystemManager = null;
  38.       
  39.       private var cursorList:Array;
  40.       
  41.       private var _currentCursorYOffset:Number = 0;
  42.       
  43.       private var cursorHolder:Sprite;
  44.       
  45.       private var currentCursor:DisplayObject;
  46.       
  47.       private var showCustomCursor:Boolean = false;
  48.       
  49.       private var _currentCursorID:int = 0;
  50.       
  51.       private var listenForContextMenu:Boolean = false;
  52.       
  53.       private var customCursorLeftStage:Boolean = false;
  54.       
  55.       private var initialized:Boolean = false;
  56.       
  57.       private var overTextField:Boolean = false;
  58.       
  59.       private var _currentCursorXOffset:Number = 0;
  60.       
  61.       private var busyCursorList:Array;
  62.       
  63.       private var sourceArray:Array;
  64.       
  65.       public function CursorManagerImpl(param1:ISystemManager = null)
  66.       {
  67.          cursorList = [];
  68.          busyCursorList = [];
  69.          sourceArray = [];
  70.          super();
  71.          if(instance && !param1)
  72.          {
  73.             throw new Error("Instance already exists.");
  74.          }
  75.          if(param1)
  76.          {
  77.             this.systemManager = param1;
  78.          }
  79.          else
  80.          {
  81.             this.systemManager = ApplicationGlobals.application.systemManager;
  82.          }
  83.       }
  84.       
  85.       public static function getInstance() : ICursorManager
  86.       {
  87.          if(!instance)
  88.          {
  89.             instance = new CursorManagerImpl();
  90.          }
  91.          return instance;
  92.       }
  93.       
  94.       public function set currentCursorYOffset(param1:Number) : void
  95.       {
  96.          _currentCursorYOffset = param1;
  97.       }
  98.       
  99.       public function get currentCursorXOffset() : Number
  100.       {
  101.          return _currentCursorXOffset;
  102.       }
  103.       
  104.       public function removeCursor(param1:int) : void
  105.       {
  106.          var _loc2_:* = null;
  107.          var _loc3_:CursorQueueItem = null;
  108.          for(_loc2_ in cursorList)
  109.          {
  110.             _loc3_ = cursorList[_loc2_];
  111.             if(_loc3_.cursorID == param1)
  112.             {
  113.                cursorList.splice(_loc2_,1);
  114.                showCurrentCursor();
  115.                break;
  116.             }
  117.          }
  118.       }
  119.       
  120.       public function get currentCursorID() : int
  121.       {
  122.          return _currentCursorID;
  123.       }
  124.       
  125.       private function updateCursorHelper() : void
  126.       {
  127.          var _loc1_:Boolean = false;
  128.          _loc1_ = systemManager.stage.hasOwnProperty("nativeWindow");
  129.          var _loc2_:Boolean = !_loc1_ || systemManager.stage["nativeWindow"]["active"];
  130.          if(_loc2_)
  131.          {
  132.             if(showSystemCursor)
  133.             {
  134.                showSystemCursor = false;
  135.                hideCursor();
  136.                Mouse.show();
  137.             }
  138.             if(showCustomCursor)
  139.             {
  140.                showCustomCursor = false;
  141.                showCursor();
  142.                Mouse.hide();
  143.             }
  144.          }
  145.          else if(cursorList.length > 0)
  146.          {
  147.             Mouse.hide();
  148.          }
  149.       }
  150.       
  151.       private function removeContextMenuHandlers() : void
  152.       {
  153.          var _loc1_:InteractiveObject = null;
  154.          var _loc2_:InteractiveObject = null;
  155.          if(listenForContextMenu)
  156.          {
  157.             _loc1_ = systemManager.document as InteractiveObject;
  158.             _loc2_ = systemManager as InteractiveObject;
  159.             if(_loc1_ && _loc1_.contextMenu)
  160.             {
  161.                _loc1_.contextMenu.removeEventListener(ContextMenuEvent.MENU_SELECT,contextMenu_menuSelectHandler,true);
  162.             }
  163.             if(_loc2_ && _loc2_.contextMenu)
  164.             {
  165.                _loc2_.contextMenu.removeEventListener(ContextMenuEvent.MENU_SELECT,contextMenu_menuSelectHandler,true);
  166.             }
  167.             listenForContextMenu = false;
  168.          }
  169.       }
  170.       
  171.       public function set currentCursorID(param1:int) : void
  172.       {
  173.          _currentCursorID = param1;
  174.       }
  175.       
  176.       private function priorityCompare(param1:CursorQueueItem, param2:CursorQueueItem) : int
  177.       {
  178.          if(param1.priority < param2.priority)
  179.          {
  180.             return -1;
  181.          }
  182.          if(param1.priority == param2.priority)
  183.          {
  184.             return 0;
  185.          }
  186.          return 1;
  187.       }
  188.       
  189.       public function removeAllCursors() : void
  190.       {
  191.          cursorList.splice(0);
  192.          showCurrentCursor();
  193.       }
  194.       
  195.       private function mouseOutHandler(param1:MouseEvent) : void
  196.       {
  197.          if(param1.relatedObject == null && cursorList.length > 0)
  198.          {
  199.             customCursorLeftStage = true;
  200.             hideCursor();
  201.             Mouse.show();
  202.          }
  203.       }
  204.       
  205.       public function setBusyCursor() : void
  206.       {
  207.          var _loc1_:CSSStyleDeclaration = StyleManager.getStyleDeclaration("CursorManager");
  208.          var _loc2_:Class = _loc1_.getStyle("busyCursor");
  209.          busyCursorList.push(setCursor(_loc2_,CursorManagerPriority.LOW));
  210.       }
  211.       
  212.       private function findSource(param1:Object) : int
  213.       {
  214.          var _loc2_:int = sourceArray.length;
  215.          var _loc3_:int = 0;
  216.          while(_loc3_ < _loc2_)
  217.          {
  218.             if(sourceArray[_loc3_] === param1)
  219.             {
  220.                return _loc3_;
  221.             }
  222.             _loc3_++;
  223.          }
  224.          return -1;
  225.       }
  226.       
  227.       private function showCurrentCursor() : void
  228.       {
  229.          var _loc1_:CursorQueueItem = null;
  230.          var _loc2_:ISystemManager = null;
  231.          if(cursorList.length > 0)
  232.          {
  233.             if(!initialized)
  234.             {
  235.                cursorHolder = new FlexSprite();
  236.                cursorHolder.name = "cursorHolder";
  237.                cursorHolder.mouseEnabled = false;
  238.                initialized = true;
  239.             }
  240.             _loc1_ = cursorList[0];
  241.             if(currentCursorID == CursorManager.NO_CURSOR)
  242.             {
  243.                Mouse.hide();
  244.             }
  245.             if(_loc1_.cursorID != currentCursorID)
  246.             {
  247.                if(cursorHolder.numChildren > 0)
  248.                {
  249.                   cursorHolder.removeChildAt(0);
  250.                }
  251.                currentCursor = new _loc1_.cursorClass();
  252.                if(currentCursor)
  253.                {
  254.                   if(currentCursor is InteractiveObject)
  255.                   {
  256.                      InteractiveObject(currentCursor).mouseEnabled = false;
  257.                   }
  258.                   _loc2_ = !!_loc1_.cursorSystemManager ? _loc1_.cursorSystemManager : ApplicationGlobals.application.systemManager;
  259.                   if(systemManager && systemManager != _loc2_)
  260.                   {
  261.                      systemManager.cursorChildren.removeChild(cursorHolder);
  262.                      removeSystemManagerHandlers();
  263.                      removeContextMenuHandlers();
  264.                      systemManager = _loc2_;
  265.                   }
  266.                   if(!systemManager.cursorChildren.contains(cursorHolder))
  267.                   {
  268.                      systemManager.cursorChildren.addChild(cursorHolder);
  269.                   }
  270.                   cursorHolder.addChild(currentCursor);
  271.                   addContextMenuHandlers();
  272.                   if(systemManager is SystemManager)
  273.                   {
  274.                      cursorHolder.x = SystemManager(systemManager).mouseX + _loc1_.x;
  275.                      cursorHolder.y = SystemManager(systemManager).mouseY + _loc1_.y;
  276.                   }
  277.                   else if(systemManager is DisplayObject)
  278.                   {
  279.                      cursorHolder.x = DisplayObject(systemManager).mouseX + _loc1_.x;
  280.                      cursorHolder.y = DisplayObject(systemManager).mouseY + _loc1_.y;
  281.                   }
  282.                   else
  283.                   {
  284.                      cursorHolder.x = _loc1_.x;
  285.                      cursorHolder.y = _loc1_.y;
  286.                   }
  287.                   systemManager.stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler,true,EventPriority.CURSOR_MANAGEMENT);
  288.                   systemManager.stage.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler,true,EventPriority.CURSOR_MANAGEMENT);
  289.                }
  290.                currentCursorID = _loc1_.cursorID;
  291.                currentCursorXOffset = _loc1_.x;
  292.                currentCursorYOffset = _loc1_.y;
  293.             }
  294.          }
  295.          else
  296.          {
  297.             showCustomCursor = false;
  298.             if(currentCursorID != CursorManager.NO_CURSOR)
  299.             {
  300.                currentCursorID = CursorManager.NO_CURSOR;
  301.                currentCursorXOffset = 0;
  302.                currentCursorYOffset = 0;
  303.                cursorHolder.removeChild(currentCursor);
  304.                removeSystemManagerHandlers();
  305.                removeContextMenuHandlers();
  306.             }
  307.             Mouse.show();
  308.          }
  309.       }
  310.       
  311.       private function contextMenu_menuSelectHandler(param1:ContextMenuEvent) : void
  312.       {
  313.          showCustomCursor = true;
  314.          systemManager.stage.addEventListener(MouseEvent.MOUSE_OVER,contextMenuMouseOverHandler,true,EventPriority.CURSOR_MANAGEMENT);
  315.       }
  316.       
  317.       public function hideCursor() : void
  318.       {
  319.          if(cursorHolder)
  320.          {
  321.             cursorHolder.visible = false;
  322.          }
  323.       }
  324.       
  325.       public function showCursor() : void
  326.       {
  327.          if(cursorHolder)
  328.          {
  329.             cursorHolder.visible = true;
  330.          }
  331.       }
  332.       
  333.       private function contextMenuMouseOverHandler(param1:MouseEvent) : void
  334.       {
  335.          systemManager.stage.removeEventListener(MouseEvent.MOUSE_OVER,contextMenuMouseOverHandler,true);
  336.          mouseMoveHandler(param1);
  337.       }
  338.       
  339.       private function completeHandler(param1:Event) : void
  340.       {
  341.          var _loc2_:int = findSource(param1.target);
  342.          if(_loc2_ != -1)
  343.          {
  344.             sourceArray.splice(_loc2_,1);
  345.             removeBusyCursor();
  346.          }
  347.       }
  348.       
  349.       public function get currentCursorYOffset() : Number
  350.       {
  351.          return _currentCursorYOffset;
  352.       }
  353.       
  354.       private function addContextMenuHandlers() : void
  355.       {
  356.          var _loc1_:InteractiveObject = null;
  357.          var _loc2_:InteractiveObject = null;
  358.          if(!listenForContextMenu)
  359.          {
  360.             _loc1_ = systemManager.document as InteractiveObject;
  361.             _loc2_ = systemManager as InteractiveObject;
  362.             if(_loc1_ && _loc1_.contextMenu)
  363.             {
  364.                _loc1_.contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT,contextMenu_menuSelectHandler,true,EventPriority.CURSOR_MANAGEMENT);
  365.                listenForContextMenu = true;
  366.             }
  367.             if(_loc2_ && _loc2_.contextMenu)
  368.             {
  369.                _loc2_.contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT,contextMenu_menuSelectHandler,true,EventPriority.CURSOR_MANAGEMENT);
  370.                listenForContextMenu = true;
  371.             }
  372.          }
  373.       }
  374.       
  375.       public function setCursor(param1:Class, param2:int = 2, param3:Number = 0, param4:Number = 0) : int
  376.       {
  377.          var _loc5_:int = nextCursorID++;
  378.          var _loc6_:CursorQueueItem;
  379.          (_loc6_ = new CursorQueueItem()).cursorID = _loc5_;
  380.          _loc6_.cursorClass = param1;
  381.          _loc6_.priority = param2;
  382.          _loc6_.x = param3;
  383.          _loc6_.y = param4;
  384.          if(systemManager)
  385.          {
  386.             _loc6_.cursorSystemManager = systemManager;
  387.          }
  388.          else
  389.          {
  390.             _loc6_.cursorSystemManager = ApplicationGlobals.application.systemManager;
  391.          }
  392.          cursorList.push(_loc6_);
  393.          cursorList.sort(priorityCompare);
  394.          showCurrentCursor();
  395.          return _loc5_;
  396.       }
  397.       
  398.       private function progressHandler(param1:ProgressEvent) : void
  399.       {
  400.          var _loc2_:int = findSource(param1.target);
  401.          if(_loc2_ == -1)
  402.          {
  403.             sourceArray.push(param1.target);
  404.             setBusyCursor();
  405.          }
  406.       }
  407.       
  408.       public function removeBusyCursor() : void
  409.       {
  410.          if(busyCursorList.length > 0)
  411.          {
  412.             removeCursor(int(busyCursorList.pop()));
  413.          }
  414.       }
  415.       
  416.       private function removeSystemManagerHandlers() : void
  417.       {
  418.          var _loc1_:Stage = systemManager.stage;
  419.          _loc1_.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler,true);
  420.          _loc1_.removeEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler,true);
  421.       }
  422.       
  423.       public function registerToUseBusyCursor(param1:Object) : void
  424.       {
  425.          if(param1 && param1 is EventDispatcher)
  426.          {
  427.             param1.addEventListener(ProgressEvent.PROGRESS,progressHandler);
  428.             param1.addEventListener(Event.COMPLETE,completeHandler);
  429.             param1.addEventListener(IOErrorEvent.IO_ERROR,completeHandler);
  430.          }
  431.       }
  432.       
  433.       public function unRegisterToUseBusyCursor(param1:Object) : void
  434.       {
  435.          if(param1 && param1 is EventDispatcher)
  436.          {
  437.             param1.removeEventListener(ProgressEvent.PROGRESS,progressHandler);
  438.             param1.removeEventListener(Event.COMPLETE,completeHandler);
  439.             param1.removeEventListener(IOErrorEvent.IO_ERROR,completeHandler);
  440.          }
  441.       }
  442.       
  443.       private function mouseMoveHandler(param1:MouseEvent) : void
  444.       {
  445.          if(customCursorLeftStage)
  446.          {
  447.             customCursorLeftStage = false;
  448.             showCursor();
  449.             if(cursorList.length > 0)
  450.             {
  451.                Mouse.hide();
  452.             }
  453.          }
  454.          if(systemManager is SystemManager)
  455.          {
  456.             cursorHolder.x = SystemManager(systemManager).mouseX + currentCursorXOffset;
  457.             cursorHolder.y = SystemManager(systemManager).mouseY + currentCursorYOffset;
  458.          }
  459.          else if(systemManager is DisplayObject)
  460.          {
  461.             cursorHolder.x = DisplayObject(systemManager).mouseX + currentCursorXOffset;
  462.             cursorHolder.y = DisplayObject(systemManager).mouseY + currentCursorYOffset;
  463.          }
  464.          else
  465.          {
  466.             cursorHolder.x = currentCursorXOffset;
  467.             cursorHolder.y = currentCursorYOffset;
  468.          }
  469.          var _loc2_:Object = param1.target;
  470.          if(!overTextField && _loc2_ is TextField && _loc2_.type == TextFieldType.INPUT)
  471.          {
  472.             overTextField = true;
  473.             showSystemCursor = true;
  474.          }
  475.          else if(overTextField && !(_loc2_ is TextField && _loc2_.type == TextFieldType.INPUT))
  476.          {
  477.             overTextField = false;
  478.             showCustomCursor = true;
  479.          }
  480.          updateCursorHelper();
  481.       }
  482.       
  483.       public function set currentCursorXOffset(param1:Number) : void
  484.       {
  485.          _currentCursorXOffset = param1;
  486.       }
  487.    }
  488. }
  489.  
  490. import mx.core.mx_internal;
  491. import mx.managers.ISystemManager;
  492.  
  493. use namespace mx_internal;
  494.  
  495. class CursorQueueItem
  496. {
  497.    
  498.    mx_internal static const VERSION:String = "3.0.0.0";
  499.     
  500.    
  501.    public var priority:int = 2;
  502.    
  503.    public var cursorClass:Class = null;
  504.    
  505.    public var cursorSystemManager:ISystemManager;
  506.    
  507.    public var cursorID:int = 0;
  508.    
  509.    public var x:Number;
  510.    
  511.    public var y:Number;
  512.    
  513.    function CursorQueueItem()
  514.    {
  515.       super();
  516.    }
  517. }
  518.